package com.google.code.swingonfire.utility.date;

import java.text.DateFormatSymbols;
import java.util.Calendar;
import java.util.Locale;
import java.util.TimeZone;

public class DateRenderInfoTimeZonePart extends AbstractStyledDateRenderInfoPart
{

    public DateRenderInfoTimeZonePart(int length)
    {
        super(length, determineStyle(length));
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected String getValue(Calendar calendar, DateFormatSymbols dateFormatSymbols, Locale locale)
    {
        TimeZone timeZone = calendar.getTimeZone();
        boolean daylight = (calendar.get(Calendar.DST_OFFSET) != 0);
        int style = (getStyle() == DateRenderInfoStyle.SHORT) ? TimeZone.SHORT : TimeZone.LONG;

        return timeZone.getDisplayName(daylight, style, locale);
    }

    private static DateRenderInfoStyle determineStyle(int length)
    {
        return (length < 4) ? DateRenderInfoStyle.SHORT : DateRenderInfoStyle.LONG;
    }

}
